<html>
<head><meta charset="utf-8"><title>associated const in array size · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html">associated const in array size</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="193197154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193197154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193197154">(Apr 07 2020 at 14:38)</a>:</h4>
<p>Associated consts cannot be used in array sizes today: <a href="https://github.com/rust-lang/rust/issues/61730" title="https://github.com/rust-lang/rust/issues/61730">https://github.com/rust-lang/rust/issues/61730</a><br>
I have some recollection that fixing this is almost as complex as implementing const generics. Is that the case?</p>



<a name="193197184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193197184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193197184">(Apr 07 2020 at 14:38)</a>:</h4>
<p><span class="user-mention" data-user-id="219747">@Simon Sapin</span> completely orthogonal</p>



<a name="193197206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193197206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193197206">(Apr 07 2020 at 14:38)</a>:</h4>
<p>also why does that issue exist?</p>



<a name="193197357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193197357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193197357">(Apr 07 2020 at 14:39)</a>:</h4>
<p><span class="user-mention" data-user-id="219747">@Simon Sapin</span> the only place where they really intersect is <code>#[feature(const_generics)]</code> turns on the fix for <a href="https://github.com/rust-lang/rust/issues/43408" title="https://github.com/rust-lang/rust/issues/43408">#43408</a> (which is like a one-line thing in one place in the compiler) which can break code</p>



<a name="193197453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193197453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193197453">(Apr 07 2020 at 14:40)</a>:</h4>
<p>the trick is letting people use parameters in array lengths <em>without</em> breaking stable code and we've been paranoid (or at least I have been) about this aspect</p>



<a name="193197563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193197563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193197563">(Apr 07 2020 at 14:41)</a>:</h4>
<p>"lazy normalization" is the feature that solves this uniformly without breaking stable code, and there are PRs open related to it (finally), but it seems to be moving slow</p>



<a name="193197690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193197690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193197690">(Apr 07 2020 at 14:42)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> What kind of breakage does this cause?</p>



<a name="193197702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193197702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193197702">(Apr 07 2020 at 14:42)</a>:</h4>
<p>query cycle errors</p>



<a name="193197729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193197729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193197729">(Apr 07 2020 at 14:42)</a>:</h4>
<p>due to circular dependencies between something using a constant expression and the constant expression itself</p>



<a name="193197785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193197785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193197785">(Apr 07 2020 at 14:42)</a>:</h4>
<p>most notably visible when arrays are used in <code>impl</code> headers and anything's <code>where</code> clauses</p>



<a name="193197874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193197874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193197874">(Apr 07 2020 at 14:43)</a>:</h4>
<p>but it might be more than that, we're not sure of the extent to which things break</p>



<a name="193197980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193197980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193197980">(Apr 07 2020 at 14:44)</a>:</h4>
<p><span class="user-mention" data-user-id="219747">@Simon Sapin</span> in the meanwhile, I've opened <a href="https://github.com/rust-lang/rust/issues/70452" title="https://github.com/rust-lang/rust/issues/70452">#70452</a> to try and carve out subsets, because <span class="user-mention" data-user-id="119031">@Esteban Küber</span> was getting impatient and wanted to add diagnostics to deal with the confusion caused by <a href="https://github.com/rust-lang/rust/issues/43408" title="https://github.com/rust-lang/rust/issues/43408">#43408</a></p>



<a name="193198018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193198018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193198018">(Apr 07 2020 at 14:44)</a>:</h4>
<p>it's in crater now and if this is a success we can move to array types</p>



<a name="193198045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193198045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193198045">(Apr 07 2020 at 14:44)</a>:</h4>
<p>I'm sorry I didn't do this years ago, this was the correct thing to do</p>



<a name="193198087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193198087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193198087">(Apr 07 2020 at 14:44)</a>:</h4>
<p>I just didn't think of blacklist vs whitelist</p>



<a name="193198137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193198137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193198137">(Apr 07 2020 at 14:45)</a>:</h4>
<p>Yeah the "add a bound" (which is already there) diagnostic is confusing</p>



<a name="193198188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193198188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193198188">(Apr 07 2020 at 14:45)</a>:</h4>
<p>No worries, thanks for taking care of it</p>



<a name="193198324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193198324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193198324">(Apr 07 2020 at 14:46)</a>:</h4>
<p><span class="user-mention" data-user-id="219747">@Simon Sapin</span> bonus: you can figure out if a crate would break w/o lazy normalization by adding <code>#![feature(const_generics)]</code> to it :P</p>



<a name="193198351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193198351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193198351">(Apr 07 2020 at 14:46)</a>:</h4>
<p>it's what I've been doing to test things out before I make the actual change</p>



<a name="193198524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193198524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193198524">(Apr 07 2020 at 14:47)</a>:</h4>
<p>we wanted to let people write <code>[T; N+1]</code> even though WF restrictions means it's kind of useless :P</p>



<a name="193198586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193198586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193198586">(Apr 07 2020 at 14:47)</a>:</h4>
<p>(until <a href="https://github.com/rust-lang/rust/issues/68436" title="https://github.com/rust-lang/rust/issues/68436">#68436</a> is solved)</p>



<a name="193198680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193198680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193198680">(Apr 07 2020 at 14:48)</a>:</h4>
<p>maybe I should've made it another opt-in but eh</p>



<a name="193198766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/associated%20const%20in%20array%20size/near/193198766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/associated.20const.20in.20array.20size.html#193198766">(Apr 07 2020 at 14:48)</a>:</h4>
<p>I think people's const-generics-using crates did break (with query cycle errors) when we made it opt into fixing <a href="https://github.com/rust-lang/rust/issues/43408" title="https://github.com/rust-lang/rust/issues/43408">#43408</a>, so it's not a theoretical problem</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>